<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EnviarCertificado
 *
 * @author boscaru
 * @export Modules
 * export-metadata RequiredRoles:ROLE_PRACTICES_COORDINATOR
 */
class EnviarCertificado extends Module {

    public function index() {

        $this->assign("action", $this->route->action("guardar"));
        $this->display();
    }

    public function guardar() {

        if ($this->request->submitted()) {
            $uploaddir = Loader::toSinglePath("uploads::", "");
            $uploadfile = $uploaddir . basename($_FILES['certificado']['name']);
            $error = $_FILES['certificado']['error'];
            $subido = false;
            if (isset($_POST['boton']) && $error == UPLOAD_ERR_OK) {
                $subido = copy($_FILES['certificado']['tmp_name'], $uploadfile);
            }

            if ($subido) {
                $this->respuesta(true);
            } else {
                $this->respuesta(false);
            }
        } else {
            $this->display("index");
        }
    }

    public function respuesta($tipo) {

        if ($tipo) {
            $this->addMessage(new Message("", "Archivo subido satisfactoriamente!!!", Message::SUCCESS));
        } else {
            $this->addMessage(new Message("", "Error al subir el archivo, vuelva a intentarlo", Message::ERROR));
        }

        $this->assign("regreso", $this->route->action("index"));
        $this->display("respuesta");
    }

}

?>
